package com.common.ibatis;



import javax.annotation.Resource;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

import com.common.page.Pagination;
import com.core.entity.PageExample;
import com.ibatis.sqlmap.client.SqlMapClient;


@Repository
public abstract class BaseDao extends SqlMapClientDaoSupport {
	
		
	    @Resource(type=SqlMapClient.class)
		public void setSqlMapClientBase(SqlMapClient sqlMapClient) {
			 super.setSqlMapClient(sqlMapClient);  
		}
	    
	    public Pagination selectByPage(Pagination page,PageExample example,String arg1,String arg2){
			Assert.notNull(page);
			Assert.notNull(example);
			int skip=page.getPageNo()*page.getPageSize();
			int pageSize=page.getPageSize();
			example.setSkip(skip);
			example.setPageSize(pageSize);
			page.setTotalCount((Integer)getSqlMapClientTemplate().queryForObject(arg2,example));
			page.adjustPageNo();
			page.setList(getSqlMapClientTemplate().queryForList(arg1,example));
			return page;
		}
 
}
